package cn.kow.kmall.security;

import cn.kow.kmall.system.entity.SysUser;
import cn.kow.kmall.system.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author: lijun
 * @Description:
 * @Date: Created in 2019-10-29 18:26
 * @Modified By:
 */
@Slf4j
@Service
public class SysUserDetailsService implements UserDetailsService {

    @Autowired
    private SysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        try {
            SysUser sysUser = sysUserService.findByUserName(username);
            return sysUser;
        } catch (Exception e) {
            throw new UsernameNotFoundException(String.format("No user found with username: %s", username));
        }
    }

}
